package leetcode.top100;

import com.alibaba.fastjson.JSON;
import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2022/11/14 10:51 PM
 * @description：
 */
public class _033_搜索旋转排序数组 {
    @Test
    public void test() {
        String str = "{\"code\":0,\"error\":\"System.UnauthorizedAccessException: 没有登录\\r\\n   at ReportAPI.ReportBLL.GetReportList(String loginID, Int32 reportID, String parameters) in D:\\\\WORK\\\\99通用模块\\\\04NetCore\\\\ReportServer\\\\ReportController\\\\Logic\\\\ReportBLL.cs:line 162\\r\\n   at ReportAPI.ReportController.GetReportList(String loginID, Int32 reportID, String parameters) in D:\\\\WORK\\\\99通用模块\\\\04NetCore\\\\ReportServer\\\\ReportController\\\\Controllers\\\\ReportController.cs:line 64\"}";
        System.out.println(JSON.parse(str));
    }

    class Solution {
        public int search(int[] nums, int target) {
            int len = nums.length;
            //找到数组中的最小值
            int r = len - 1;
            int l = 0;
            while (l < r) {
                int mid = l + r >> 1;
                if (nums[mid] <= nums[r]) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            //根据最小值的位置重新划分区间
            if (nums[l] <= target && nums[len - 1] >= target) {
                r = len - 1;
            } else {
                r = l - 1;
                l = 0;
            }
            while (l < r) {
                int mid = l + r >> 1;
                if (nums[mid] >= target) {
                    r = mid;
                } else {
                    l = mid + 1;
                }
            }
            return nums[l] == target ? l : -1;
        }
    }
}
